﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using yq.IBase.DBHelper.Tool;
using yq.CacheHelp;
using yq.IBase.Basis;

namespace yq.IBase.DBHelper
{
    internal class DbTool
    {
        ITool tool = null;

        public DbTool()
        {
            switch (DbHelper.dbProviderName)
            {
                case "System.Data.SQLite": tool = new SQLiteTool(); break;
                case "System.Data.SqlClient": tool = new SQLTool(); break;
                case "MySql.Data.Entity": tool = new MysqlTool(); break;
                default: new Exception("该数据库类型还没有对应的方法"); break;
            }
        }

        /// <summary>
        ///返回数据库表列表名
        /// </summary>
        /// <returns>K:表名 v:主键</returns>
        public Dictionary<string, string> GetTableList()
        {
            using (DbHelper cn = new DbHelper())
            {
                return tool.GetTableList(cn);
            }
        }

        /// <summary>
        /// 获取行锁的方式
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public SelectSQL GetRowLock(SelectSQL sql)
        {
            return tool.GetRowLock(sql);
        }


        /// <summary>
        /// Top排序
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        public SelectSQL Top(SelectSQL sql, int top)
        {
            return tool.Top(sql, top);
        }

    }
}
